<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>大事件项目_注册页面</title>
    <!-- 凡是css/js, 要先引入第三方, 再引入自己的 -->
    <link rel="stylesheet" href="./assets/lib/layui/css/layui.css" />
    <link rel="stylesheet" href="./login/login.css" />
  </head>

  <body>
    <!-- logo -->
    <div id="logo">
      <img src="./assets/images/logo.png" />
    </div>

    <!-- 注册的盒子 -->
    <div id="register">
      <!-- 盒子的标题 -->
      <div class="title"></div>
      <!-- 登录的表单 -->
      <form class="layui-form">
        <!-- 第一行：用户名 -->
        <div class="layui-form-item">
          <i class="layui-icon layui-icon-username"></i>
          <input
            type="text"
            name="username"
            required
            lay-verify="required|username"
            placeholder="请输入用户名"
            autocomplete="off"
            class="layui-input"
          />
        </div>
        <!-- 第二行：密码 -->
        <div class="layui-form-item">
          <i class="layui-icon layui-icon-password"></i>
          <input
            type="password"
            name="password"
            required
            lay-verify="required|pass"
            placeholder="请输入密码"
            autocomplete="off"
            class="layui-input"
          />
        </div>
        <!-- 第三行：确认密码 -->
        <div class="layui-form-item">
          <i class="layui-icon layui-icon-password"></i>
          <input
            type="password"
            name="repassword"
            required
            lay-verify="required|pass"
            placeholder="请再次输入密码"
            autocomplete="off"
            class="layui-input"
          />
        </div>
        <!-- 第三行：按钮 -->
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid layui-bg-blue" lay-submit>
            注册
          </button>
        </div>
        <!-- 第四行：去注册账号 -->
        <div class="layui-form-item">
          <a href="./login.html" id="goto-register">去登录账号</a>
        </div>
      </form>
    </div>
    <script src="./assets/lib/jquery.js"></script>
    <script src="./assets/lib/layui/layui.all.js"></script>
    <script src="./assets/lib/axios.js"></script>
    <script src="./assets/lib/md5.js"></script>
    <script src="./common/utils.js"></script>
    <script src="./assets/lib/form-serialize.js"></script>
    <script>
      document
        .querySelector('.layui-btn')
        .addEventListener('click', async function (e) {
          e.preventDefault()
          const data = serialize(document.querySelector('form'), { hash: true })
          const res = await axios({
            url: '/api/reg',
            method: 'post',
            data
          })
          alert('注册成功，即将跳转登录页')
          location.href = './login.html'
        })
    </script>
  </body>
</html>
